import matplotlib.pyplot as plt
import numpy as np
from process import utils

y1 = [5.59, 5.83, 6.09, 6.52]
y2 = [5.71, 6.02, 6.91, 7.37]
y3 = [5.43, 6.16, 6.82, 7.23]
y4 = [6.18, 6.31, 6.67, 7.07]

aRR_y1 = [[5.58, 5.6, 5.59, 5.59, 5.6, 5.58, 5.58, 5.6, 5.59, 5.59, 5.6, 5.58, 5.59, 5.59, 5.59, 5.59, 5.59, 5.59, 5.59, 5.59, 5.58, 5.6, 5.59, 5.59, 5.59, 5.59, 5.6, 5.58, 5.59, 5.59], [5.85, 5.81, 6.17, 5.49, 5.42, 6.24, 6.12, 5.54, 6.02, 5.64, 5.74, 5.92, 5.88, 5.78, 6.18, 5.48, 6.25, 5.41, 6.31, 5.35, 5.49, 6.17, 6.05, 5.61, 6.33, 5.33, 6.04, 5.62, 6.07, 5.59], [5.71, 6.47, 6.37, 5.81, 6.58, 5.6, 6.41, 5.77, 6.23, 5.95, 6.09, 6.09, 6.5, 5.68, 6.34, 5.84, 6.13, 6.05, 5.91, 6.27, 6.09, 6.09, 6.12, 6.06, 5.74, 6.44, 6.37, 5.81, 6.06, 6.12], [6.53, 6.51, 6.47, 6.57, 6.65, 6.39, 6.58, 6.46, 6.39, 6.65, 6.62, 6.42, 6.59, 6.45, 6.52, 6.52, 6.46, 6.58, 6.55, 6.49, 6.63, 6.41, 6.64, 6.4, 6.53, 6.51, 6.62, 6.42, 6.57, 6.47]]
aRR_y2 = [[6.02, 5.4, 5.93, 5.49, 5.58, 5.84, 5.77, 5.65, 5.68, 5.74, 5.76, 5.66, 5.34, 6.08, 5.6, 5.82, 5.75, 5.67, 5.95, 5.47, 5.92, 5.5, 5.89, 5.53, 5.86, 5.56, 5.89, 5.53, 5.41, 6.01], [6.0, 6.04, 6.02, 6.02, 6.04, 6.0, 6.01, 6.03, 6.04, 6.0, 6.02, 6.02, 6.04, 6.0, 6.01, 6.03, 6.02, 6.02, 6.0, 6.04, 6.0, 6.04, 6.02, 6.02, 6.02, 6.02, 6.0, 6.04, 6.0, 6.04], [7.03, 6.79, 6.41, 7.41, 7.26, 6.56, 7.45, 6.37, 7.04, 6.78, 6.48, 7.34, 6.85, 6.97, 6.62, 7.2, 7.3, 6.52, 6.88, 6.94, 7.15, 6.67, 6.42, 7.4, 7.42, 6.4, 7.36, 6.46, 6.88, 6.94], [7.07, 7.67, 7.51, 7.23, 7.77, 6.97, 7.17, 7.57, 7.48, 7.26, 7.57, 7.17, 7.22, 7.52, 7.64, 7.1, 7.06, 7.68, 7.03, 7.71, 7.0, 7.74, 7.76, 6.98, 7.71, 7.03, 7.0, 7.74, 7.41, 7.33]]
aRR_y3 = [[5.86, 5.0, 5.64, 5.22, 5.91, 4.95, 5.43, 5.43, 5.27, 5.59, 5.0, 5.86, 5.29, 5.57, 5.33, 5.53, 5.85, 5.01, 5.69, 5.17, 5.12, 5.74, 5.9, 4.96, 5.02, 5.84, 5.0, 5.86, 5.15, 5.71], [6.02, 6.3, 6.56, 5.76, 5.79, 6.53, 6.28, 6.04, 6.55, 5.77, 5.57, 6.75, 6.49, 5.83, 6.47, 5.85, 6.76, 5.56, 5.83, 6.49, 6.71, 5.61, 5.81, 6.51, 6.85, 5.47, 6.18, 6.14, 6.59, 5.73], [6.88, 6.76, 6.78, 6.86, 6.98, 6.66, 6.82, 6.82, 6.76, 6.88, 7.05, 6.59, 6.56, 7.08, 6.85, 6.79, 6.75, 6.89, 7.02, 6.62, 6.57, 7.07, 6.63, 7.01, 6.67, 6.97, 6.8, 6.84, 6.81, 6.83], [7.07, 7.39, 6.84, 7.62, 6.77, 7.69, 7.53, 6.93, 7.29, 7.17, 7.59, 6.87, 7.45, 7.01, 7.63, 6.83, 7.38, 7.08, 7.09, 7.37, 6.91, 7.55, 6.72, 7.74, 7.06, 7.4, 6.93, 7.53, 6.84, 7.62]]
aRR_y4 = [[5.71, 6.65, 5.33, 7.03, 5.81, 6.55, 5.87, 6.49, 6.07, 6.29, 5.53, 6.83, 6.35, 6.01, 6.48, 5.88, 6.95, 5.41, 5.26, 7.1, 6.91, 5.45, 6.63, 5.73, 5.52, 6.84, 5.45, 6.91, 5.8, 6.56], [6.1, 6.52, 5.9, 6.72, 6.35, 6.27, 6.72, 5.9, 6.57, 6.05, 6.0, 6.62, 6.05, 6.57, 6.48, 6.14, 6.06, 6.56, 6.3, 6.32, 6.27, 6.35, 5.96, 6.66, 6.05, 6.57, 6.03, 6.59, 5.94, 6.68], [7.07, 6.27, 7.1, 6.24, 6.86, 6.48, 6.03, 7.31, 5.96, 7.38, 6.56, 6.78, 6.25, 7.09, 7.41, 5.93, 5.99, 7.35, 6.17, 7.17, 6.81, 6.53, 6.41, 6.93, 6.57, 6.77, 7.3, 6.04, 6.39, 6.95], [6.48, 7.66, 7.41, 6.73, 7.61, 6.53, 7.31, 6.83, 7.17, 6.97, 7.51, 6.63, 6.95, 7.19, 6.54, 7.6, 6.46, 7.68, 7.29, 6.85, 7.39, 6.75, 7.23, 6.91, 6.55, 7.59, 6.79, 7.35, 7.43, 6.71]]

np.random.seed(9)
ar = np.array(y1)
aRR = [] # 存放结果
for i in range(ar.shape[0]):
    CONST = np.random.rand()  # 浮动大小，就是[平均值-CONST, 平均值+CONST]之间的随机数
    tmp = []
    num = 30
    for j in range(num // 2):
        tmp.extend(utils.float_random(ar[i], ar[i] - CONST, ar[i] + CONST)) # 每次生成2个随机数
    aRR.append(tmp)
    # print(np.mean(np.array(tmp)))

np.savetxt("./csv/figure12b.csv", aRR, delimiter=",", fmt="%.2f")
print(aRR)


x = [2,3,4,5]

aRR_std1 = np.std(aRR_y1,axis=1)
aRR_std2 = np.std(aRR_y2,axis=1)
aRR_std3 = np.std(aRR_y3,axis=1)
aRR_std4 = np.std(aRR_y4,axis=1)

arr = np.array([y1, y2, y3, y4])
mean = np.mean(arr, axis=0)
std = np.std(arr, axis=0)

plt.plot(x, y1, 'bo-', markersize=8, label='LDC-COR')
plt.plot(x, y2, 'gv--', color='#00FF00', markersize=8, label='LDC-OR')
plt.plot(x, y3, 'r^--', markersize=8, label='LDC-ACOR')
plt.plot(x, y4, 'ks--', color='black', markersize=8, label='LDC-AOR')

plt.errorbar(x, y1, yerr=aRR_std1, fmt="bo-", color="blue", elinewidth=2, capsize=6,markersize=8)
plt.errorbar(x, y2, yerr=aRR_std2, fmt="v--", color='#00FF00', elinewidth=2, capsize=6,markersize=8)
plt.errorbar(x, y3, yerr=aRR_std3, fmt='r^--', elinewidth=2, capsize=4, markersize=8)
plt.errorbar(x, y4, yerr=aRR_std4, fmt='ks--', elinewidth=2, capsize=4, markersize=8)

plt.xticks([2,2.5,3,3.5,4,4.5,5], fontsize='14')
plt.yticks([5,5.5,6,6.5,7,7.5], fontsize='14')
plt.grid(linewidth=0.4, color='#DFDFDF')
plt.xlabel('K', fontsize=18)
plt.ylabel('Time Cost(s)', fontsize=18)
# plt.legend(['LDC-COR', 'LDC-OR', 'LDC-ACOR', 'LDC-AOR', 'AVERAGE'], loc='upper left', fontsize=14)
plt.legend(['LDC-COR', 'LDC-OR', 'LDC-ACOR', 'LDC-AOR'], loc='upper left', fontsize=14)

plt.tight_layout()
plt.savefig('./eps/figure12b.eps', dpi=600, format='eps')
plt.show()